package com.siruier.boss.api

import com.alibaba.fastjson.JSONObject
import com.siruier.boss.api.core.ApiHelper
import com.siruier.boss.api.core.ResultBean
import com.siruier.boss.bean.*
import kotlinx.coroutines.CoroutineScope
import retrofit2.http.*
import java.math.BigDecimal

val MALL_API_SERVICE: MallApiService by lazy { ApiHelper.create(MallApiService::class.java) }

val CoroutineScope.mallApi get() = MALL_API_SERVICE

interface MallApiService {

    /**
     * 获取爆款新品
     */
    @POST("/api/goods/hotPage")
    @FormUrlEncoded
    suspend fun hotPage(
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<MallGoodsBean>?>

    /**
     * 获取商品分类列表
     */
    @GET("/api/goods/category")
    suspend fun category(): ResultBean<MutableList<MallCategoryBean>?>

    /**
     * 获取全部分类
     */
    @GET("/api/goods/categoryAll")
    suspend fun categoryAll(): ResultBean<MutableList<MallCategoryBean>?>

    /**
     * 话费充值价格列表
     */
    @GET("/api/mobile/priceList")
    suspend fun priceList(): ResultBean<MutableList<MobilePayPriceVo>?>

    /**
     * 话费充值记录查询
     */
    @POST("/api/mobile/recharge/list")
    @FormUrlEncoded
    suspend fun rechargeList(
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<BlTelRecharge>?>

    /**
     * 获取0元福利
     */
    @POST("/api/goods/zeroPage")
    @FormUrlEncoded
    suspend fun zeroPage(
        @Field("categoryId") categoryId: Int?,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<MallGoodsBean>?>

    /**
     * 获取商品列表
     */
    @POST("/api/goods/list")
    @FormUrlEncoded
    suspend fun goodsList(
        @Field("keywords") keywords: String?,
        @Field("categoryId") categoryId: Int?,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<MallGoodsBean>?>

    /**
     * 获取限时抢购
     */
    @POST("/api/goods/homePage")
    @FormUrlEncoded
    suspend fun homePage(
        @Field("categoryId") categoryId: Int?,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<MallGoodsBean>?>

    /**
     * 获取加盟商品
     * @param type 类型 2-代理加盟商品 3-门店合作商品
     */
    @POST("/api/goods/joinPage")
    @FormUrlEncoded
    suspend fun joinPage(
        @Field("categoryId") categoryId: Int?,
        @Field("type") type: String,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<PageBean<MallGoodsBean>?>

    /**
     * 获取商品详情
     */
    @POST("/api/goods/detail")
    @FormUrlEncoded
    suspend fun goodsDetail(@Field("goodsId") goodsId: Int): ResultBean<MallGoodsBean?>

    /**
     * 获取商品规格列表
     */
    @POST("/api/goods/specn")
    @FormUrlEncoded
    suspend fun goodsSpecn(@Field("goodsId") goodsId: Int): ResultBean<MallGoodsSpecInfoBean?>

    /**
     * 获取分享商品二维码
     */
    @POST("/api/goods/shareCode")
    @FormUrlEncoded
    suspend fun shareCode(@Field("goodsId") goodsId: Int): ResultBean<ShareCode?>

    /**
     * 用户注销
     */
    @GET("/api/user/accountOff")
    suspend fun accountOff(): ResultBean<Any?>

    /**
     * 订单预览
     */
    @POST("/api/order/preview")
    @FormUrlEncoded
    suspend fun orderPreview(
        @Field("goodsId") goodsId: Int,
        @Field("num") num: Int,
        @Field("specnId") specnId: String
    ): ResultBean<OrderDetailBean?>

    /**
     * 提交订单
     */
    @POST("/api/order/submit")
    @FormUrlEncoded
    suspend fun orderSubmit(
        @Field("addressId") addressId: Int?,
        @Field("comment") comment: String,
        @Field("goodsId") goodsId: Int,
        @Field("leaveMessage") leaveMessage: String?,
        @Field("num") num: Int,
        @Field("specnId") specnId: String,
        @Field("type") type: Int,
    ): ResultBean<OrderDetailBean?>

    /**
     * 话费充值下单
     */
    @POST("/api/mobile/order")
    @FormUrlEncoded
    suspend fun mobileOrder(
        @Field("cardNum") cardNum: BigDecimal?,
        @Field("phone") phone: String,
    ): ResultBean<PayOrder?>

    /**
     * 订单支付
     */
    @POST("/api/pay/order")
    @FormUrlEncoded
    suspend fun orderPay(
        @Field("amount") amount: String?,
        @Field("balance") balance: String? = null,
        @Field("integral") integral: String? = null,
        @Field("orderNo") orderNo: String? = null,
        @Field("payWay") payWay: String? = null,
        @Field("phone") phone: String? = null,
        @Field("orderType") orderType: Int = 1,
        @Field("tradeType") tradeType: String = "APP",
    ): ResultBean<PayOrder?>

    /**
     * 获取挂卖价格
     */
    @POST("/api/give/preSale")
    @FormUrlEncoded
    suspend fun preSale(
        @Field("orderSn") orderSn: String,
    ): ResultBean<PreSaleVO?>

    /**
     * 获取加盟商品转赠抵扣
     */
    @POST("/api/give/discount")
    @FormUrlEncoded
    suspend fun discount(
        @Field("goodsId") goodsId: Int?,
        @Field("orderSn") orderSn: String?,
        @Field("specnId") specnId: String?,
    ): ResultBean<DiscountVO?>

    /**
     * 挂卖
     */
    @POST("/api/give/sale")
    @FormUrlEncoded
    suspend fun sale(
        @Field("orderSn") orderSn: String,
    ): ResultBean<Any?>

    /**
     * 取消挂卖
     */
    @POST("/api/give/cancelSale")
    @FormUrlEncoded
    suspend fun cancelSale(
        @Field("orderSn") orderSn: String,
    ): ResultBean<Any?>

    /**
     * 取消赠送
     */
    @POST("/api/give/cancelTransfer")
    @FormUrlEncoded
    suspend fun cancelTransfer(
        @Field("orderSn") orderSn: String,
    ): ResultBean<Any?>

    /**
     * 获取支付渠道
     */
    @POST("/api/pay/channel")
    @FormUrlEncoded
    suspend fun payChannel(
        @Field("appType") appType: String = "android",
    ): ResultBean<MutableList<PayChannel>?>

    /**
     * 订单状态查询
     */
    @POST("/api/pay/query")
    @FormUrlEncoded
    suspend fun payQuery(
        @Field("orderNo") orderNo: String?,
    ): ResultBean<PayOrder?>

    /**
     * 获取用户的收货地址
     */
    @GET("/api/address/list")
    suspend fun addressList(): ResultBean<MutableList<ShopAddressBean>?>

    /**
     * 获取用户默认收货地址
     */
    @GET("/api/address/getDefault")
    suspend fun addressGetDefault(): ResultBean<ShopAddressBean?>

    /**
     * 新增地址
     */
    @POST("/api/address/add")
    @FormUrlEncoded
    suspend fun addressSave(
        @FieldMap shopAddressBean: JSONObject
    ): ResultBean<Any?>

    /**
     * 根据ID更新地址
     */
    @POST("/api/address/update")
    @FormUrlEncoded
    suspend fun addressUpdate(
        @FieldMap shopAddressBean: JSONObject
    ): ResultBean<Any?>

    /**
     * 删除收货地址
     */
    @POST("/api/address/delete")
    @FormUrlEncoded
    suspend fun addressDelete(
        @Field("id") id: Int,
    ): ResultBean<Any?>

    /**
     * 获取订单详情
     */
    @POST("/api/order/detail")
    @FormUrlEncoded
    suspend fun orderDetail(
        @Field("orderSn") orderSn: String,
    ): ResultBean<OrderDetailBean?>

    /**
     * 获取转赠订单详情
     */
    @POST("/api/give/giveOrderDetail")
    @FormUrlEncoded
    suspend fun giveOrderDetail(
        @Field("orderSn") orderSn: String,
    ): ResultBean<OrderDetailBean?>

    /**
     * 我送出的订单列表（分页）
     */
    @POST("/api/give/giveOrder")
    @FormUrlEncoded
    suspend fun giveOrder(
        @Field("status") status: Int?,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<MallPageBean<GiftOrderDetailBean>?>

    /**
     * 我收到的订单列表（分页）
     */
    @POST("/api/give/receiveOrder")
    @FormUrlEncoded
    suspend fun receiveOrder(
        @Field("dealType") dealType: Int?,
        @Field("giveStatus") giveStatus: Int?,
        @Field("ownStatus") ownStatus: Int?,
        @Field("saleStatus") saleStatus: Int?,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<MallPageBean<GiftOrderDetailBean>?>

    /**
     * 分页查询手机卡订单列表
     */
    @POST("/api/order/mobilePackagePage")
    @FormUrlEncoded
    suspend fun mobilePackagePage(
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<MallPageBean<GiftOrderDetailBean>?>

    /**
     * 手机卡订单补充资料
     */
    @POST("/api/order/fillInfo")
    @FormUrlEncoded
    suspend fun fillInfo(
        @Field("orderSn") orderSn: String,
        @Field("phone") phone: String?,
        @Field("receiptImg") receiptImg: String?,
        @Field("signStr") signStr: String?,
    ): ResultBean<Any?>

    /**
     * 补充资料详情
     */
    @POST("/api/order/fillInfoDetail")
    @FormUrlEncoded
    suspend fun fillInfoDetail(
        @Field("orderSn") orderSn: String,
    ): ResultBean<UserMobilePackage?>

    /**
     * 分页查询订单列表
     */
    @POST("/api/order/list")
    @FormUrlEncoded
    suspend fun orderList(
        @Field("status") status: Int,
        @Field("currentPage") currentPage: Int,
        @Field("pageSize") pageSize: Int = 20,
    ): ResultBean<MallPageBean<OrderDetailBean>?>

    /**
     * 取消订单
     */
    @POST("/api/order/cancel")
    @FormUrlEncoded
    suspend fun orderCancel(
        @Field("orderSn") orderSn: String,
    ): ResultBean<Any?>

    /**
     * 赠送取消订单
     */
    @POST("/api/give/cancelOrder")
    @FormUrlEncoded
    suspend fun cancelOrder(
        @Field("orderSn") orderSn: String,
    ): ResultBean<Any?>

    /**
     * 订单赠送
     */
    @POST("/api/give/transfer")
    @FormUrlEncoded
    suspend fun transfer(
        @Field("leaveMessage") leaveMessage: String,
        @Field("orderSn") orderSn: String,
    ): ResultBean<Any?>

    /**
     * 立即发货
     */
    @POST("/api/give/sendShip")
    @FormUrlEncoded
    suspend fun sendShip(
        @Field("addressId") addressId: Int?,
        @Field("orderSn") orderSn: String,
    ): ResultBean<Any?>

    /**
     * 查询物流信息
     */
    @POST("/api/order/shipRecord")
    @FormUrlEncoded
    suspend fun shipRecord(
        @Field("orderSn") orderSn: String,
    ): ResultBean<ShipRecord>
}